package com.ruoyi.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ExaminationInfo;
import com.ruoyi.system.service.IExaminationInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/examination")
public class ExaminationInfoController extends BaseController {

    private final IExaminationInfoService examinationInfoService;

    /**
     * 查询测试信息列表
     */
    @GetMapping("/list")
    public TableDataInfo<ExaminationInfo> list(ExaminationInfo examinationInfo, PageQuery pageQuery) {
        return examinationInfoService.selectPageExaminationInfoList(examinationInfo, pageQuery);
    }

    /**
     * 导出测试信息列表
     */
    @PostMapping("/export")
    public void export(ExaminationInfo examinationInfo, HttpServletResponse response) {
        List<ExaminationInfo> list = examinationInfoService.selectExaminationInfoList(examinationInfo);
        ExcelUtil.exportExcel(list, "考试信息", ExaminationInfo.class, response);
    }

    /**
     * 获取测试信息详细信息
     *
     * @param testId 测试ID
     */
    @GetMapping(value = "/{testId}")
    public R<ExaminationInfo> getInfo(@PathVariable Long testId) {
        return R.ok(examinationInfoService.selectExaminationInfoById(testId));
    }

    /**
     * 新增测试信息
     */
    @Log(title = "测试信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody ExaminationInfo examinationInfo) {
        return toAjax(examinationInfoService.insertExaminationInfo(examinationInfo));
    }

    /**
     * 修改测试信息
     */
    @Log(title = "测试信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody ExaminationInfo examinationInfo) {
        return toAjax(examinationInfoService.updateExaminationInfo(examinationInfo));
    }

    /**
     * 删除测试信息
     *
     * @param testIds 测试ID串
     */
    @Log(title = "测试信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{testIds}")
    public R<Void> remove(@PathVariable Long[] testIds) {
        return toAjax(examinationInfoService.deleteExaminationInfoByIds(testIds));
    }
}
